
# from skimage import data,color,io
# from matplotlib import pyplot as plt
# import numpy as np
# # img = data.coffee()
# image = io.imread(r'C:\Users\26356\Desktop\python\lenagray.jpg')
# grayimg = color.rgb2gray(image) #将彩色图像转化为灰度图像
# plt.rcParams['font.sans-serif'] = ['SimHei'] 
# plt.rcParams['axes.unicode_minus'] = False
# plt.subplot(1, 2, 1)
# plt.imshow(grayimg, cmap = 'gray')
# plt.title('灰度图像')
# rows, cols = grayimg.shape
# labels = np.zeros([rows, cols])
# for i in range(rows):
#     for j in range(cols):
#         if(grayimg[i, j] < 0.4):
#             labels[i, j] = 0
#         elif(grayimg[i, j] < 0.8):
#             labels[i, j] = 1
#         else:
#             labels[i, j] = 2
# psdimg = color.label2rgb(labels)#不同的label采用不同的颜色
# plt.subplot(1, 2, 2)
# plt.imshow(psdimg)
# plt.title('强度分层图像')
# plt.show()
# plt.savefig('灰度分层.tif')




from skimage import data,color,io
from matplotlib import pyplot as plt
import numpy as np

# img = data.coffee()
image = io.imread(r'C:\Users\26356\Desktop\python\lenagray.jpg')
grayimg = color.rgb2gray(image) #将彩色图像转化为灰度图像
plt.rcParams['font.sans-serif'] = ['SimHei'] 
plt.rcParams['axes.unicode_minus'] = False
plt.subplot(1, 2, 1)
plt.imshow(grayimg, cmap = 'gray')
plt.title('灰度图像')
rows, cols = grayimg.shape
labels = np.zeros([rows, cols])
for i in range(rows):
    for j in range(cols):
        if(grayimg[i, j] < 0.5):
            labels[i, j] = 0
        elif(grayimg[i, j] < 0.6):
            labels[i, j] = 1
        elif(grayimg[i, j] < 0.7):
            labels[i, j] = 2
        elif(grayimg[i, j] < 0.8):
            labels[i, j] = 3
        elif(grayimg[i, j] < 0.9):
            labels[i, j] = 4
        else:
            labels[i, j] = 5
psdimg = color.label2rgb(labels)#不同的label采用不同的颜色
plt.subplot(1, 2, 2)
plt.imshow(psdimg)
plt.title('强度分层图像')
plt.show()
# plt.savefig('灰度分层.tif')
